
-module(chat_channel_test).

-include_lib("eunit/include/eunit.hrl").

-export([run_tests/0]).


run_tests() ->
    ?debugMsg("chat_channel_test start --"),
    chat:start(),
    Pid = spawn_link(fun loop/0),
    Pid ! "I'm ready!",

    MsgAmount = 15,
    MsgList = [{Id, "msg " ++ integer_to_list(Id)} || Id <- lists:seq(1, MsgAmount)],

    chat:public_login(world, 0, Pid),
    [chat:public_talk(world, 0, Msg) || Msg <- MsgList],

    ?debugVal(chat:public_fetch(world, 0, 0)),
    ?debugVal(chat:public_fetch(world, 0, 5)),

    close("no process exit"),
    ?debugMsg("chat_channel_test over"),
    ok.

loop() ->
    receive
        Msg ->
            ?debugVal(Msg),
            loop()
    after
        1000 ->
            exit(timeout)
    end.

close(Msg) ->
    receive
        Recv ->
            ?debugVal(Recv)
    after
        5000 ->
            ?debugMsg(Msg)
    end.



